import {baseUrl} from "@/config/env";

import optionUtils from "@/option/optionUtils";
import userOption from "@/option/sys/userOption";
import userApi from "@/api/sys/userApi";

const startAdminUserOption = userOption();
const confKeyMap = {
    "def_fixed_admin_user_load": (val, formModel) => {
        return {
            confVal: {
                type: "table",
                label: "审批人",
                display: true,
                children: startAdminUserOption,
                onLoad: (onLoadParams, callback) => {
                    onLoadParams.pageDefinition = userApi.list
                    onLoadParams.valueDefinition = userApi.getUserInfo
                    onLoadParams.option = startAdminUserOption;
                    optionUtils.tableOnLoad(onLoadParams, callback)
                }
            }
        }
    },
    "custom_auth_candidate": (val, formModel) => {
        formModel.confVal = ""
        return {
            confVal: {
                type: "input",
                label: "审批人",
                display: false,
            },
        }
    },
    "task_node_auth_user": (val, formModel) => {
        formModel.confVal = ""
        return {
            confVal: {
                type: "input",
                label: "审批人",
                display: false,
            },
        }
    },
    "def_fixed_role_user_load": (val, formModel) => {
        return {
            confVal: {
                type: "tree",
                label: "角色",
                display: true,
                dicUrl: baseUrl + "/user/role/getUserRoles",
                props: {
                    label: "name",
                    value: "code",
                }

            }
        }
    },
    "def_fixed_admin_dept_load": (val, formModel) => {
        return {
            confVal: {
                type: "tree",
                label: "组织机构",
                display: true,
                dicUrl: baseUrl + "/start/sysDept/listTree",
                props: {
                    label: "deptName",
                    value: "deptCode",
                }

            }
        }
    },
    "def_fixed_admin_dept_manager_candidate": (val, formModel) => {
        return {
            confVal: {
                type: "tree",
                label: "部门管理级别",
                display: true,
                dicUrl: baseUrl + "/start/sysDictionaryItem/listByDictionaryCode?dictCode=user_manage_dept_levels",
                props: {
                    label: "dictName",
                    value: "dictCode",
                }

            }
        }
    },

}

function getOption(vm) {
    let option = {
        menuBtn: false,
        column: [
            {
                label: "接收类型",
                type: 'select',
                prop: "confKey",
                dicUrl: baseUrl + "/startActDicApi/getCarbonCopyType",
                span: 24,
                control: (val, formModel) => {
                    let result = {}
                    if (confKeyMap[val]) {
                        result = confKeyMap[val](val, formModel)
                    }
                    vm.$nextTick(() => {
                        vm.$refs.configForm.updateDic("confVal")
                    })
                    return result
                },

            },
            {
                label: "接收人",
                type: 'select',
                prop: "confVal",
                span: 24,
                display: false,
            }
        ]
    }
    return option
}

const actTaskCandidateOption = {
    getOption
}
export default actTaskCandidateOption
